//
//
//
//  @ Project : Untitled
//  @ File Name : Terrain.h
//  @ Date : 2011/4/15
//  @ Author : 
//
//


#if !defined(_TERRAIN_H)
#define _TERRAIN_H

#include "type.h"

#include "vector3.h"

#include "Renderable.h"

/*
#include <Physics/Collide/Shape/HeightField/SampledHeightField/hkpSampledHeightFieldShape.h>
#include <Physics/Collide/Shape/HeightField/SampledHeightField/hkpSampledHeightFieldBaseCinfo.h>


class hkpWorld;
class hkpRigidBody;
*/

namespace TerrainSystem
{
	//class TerrainPhysicsShape;

	class Terrain 
		: public renderer
	{
	public:

		Terrain(void);
		~Terrain(void);

		void SetStartPos( const Common::Vector3& vStartPos );
		Common::Vector3 GetStartPos( void ) const;

		void SetExtent( uint16 uWidth, uint16 uHeight );
		void GetExtent( uint16& uWidth, uint16& uHeight ) const;

		bool SetHeight( uint16 uIdxX, uint16 uIdxY, float fHeight );
		bool GetHeight( uint16 uIdxX, uint16 uIdxY, float &fHeight ) const;

		void SetScale( Common::Vector3 vScale );
		Common::Vector3 GetScale( void ) const;

		void SetUnitSize( float fUnitSize );
		float GetUnitSize( void ) const;

		/*
		void InitPhysicsShape( hkpWorld* pPhyWorld );
		void DestroyPhysicsShape( hkpWorld* pPhyWorld );
		*/

	protected:

		Common::Vector3 m_vStartPos;
		uint16 m_uWidth;
		uint16 m_uHeight;
		float m_fUnitSize;

		float* m_fPoints;

		Common::Vector3 m_vScale;

		//TerrainPhysicsShape* m_pTerrainPhysicsShape;
		//hkpRigidBody* m_pTerrainRigidBody;
	};

	/*
	class TerrainPhysicsShape
		:public hkpSampledHeightFieldShape
	{
	public:
		TerrainPhysicsShape( const hkpSampledHeightFieldBaseCinfo& ci, Terrain* pTerrain )
			:hkpSampledHeightFieldShape(ci), m_pTerrain(pTerrain)
		{
		}

		// Generate a rough terrain
		HK_FORCE_INLINE hkReal getHeightAtImpl( int x, int z ) const
		{
			float fHeight = 0.0f;
			if( !m_pTerrain->GetHeight( x, z, fHeight) )
				assert( false );

			return fHeight;
		}

		// Assuming each heightfield quad is defined as four points { 00, 01, 11, 10 },
		// this should return true if the two triangles share the edge p00-p11.
		// Otherwise it should return false if the triangles share the edge p01-p10
		HK_FORCE_INLINE hkBool getTriangleFlipImpl() const
		{	
			return false;
		}

		virtual void collideSpheres( const CollideSpheresInput& input, SphereCollisionOutput* outputArray) const
		{
			hkSampledHeightFieldShape_collideSpheres(*this, input, outputArray);
		}

	private:

		Terrain* m_pTerrain;
	};
	*/
}
#endif  //_TERRAIN_H
